package com.stress.testing.plugin.nosql.redis.util;

public final class NumberUtils {
    private NumberUtils() {
    }

    public static byte[] intToByteArray(int number) {
        byte[] bytes = new byte[4];
        bytes[0] = (byte) number;
        bytes[1] = (byte) (number >> 8);
        bytes[2] = (byte) (number >> 16);
        bytes[3] = (byte) (number >> 24);
        return bytes;
    }

    /**
     * TODO: 这里合理吗？客户端调用的时候，使用这种算法的逆向算法得到的byte[]吗？可能是int->string,然后getbyte
     * @param bytes
     * @return
     */
    public static int byteArrayToInt(byte[] bytes) {
        int i0 = bytes[0] & 0xFF;
        int i1 = (bytes[1] & 0xFF) << 8;
        int i2 = (bytes[2] & 0xFF) << 16;
        int i3 = (bytes[3] & 0xFF) << 24;
        return i0 | i1 | i2 | i3;
    }
}
